package com.hsd.netty.client.handler;

import com.hsd.netty.client.method.MethodClass;
import com.hsd.netty.client.proxy.ChannelProxy;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author s.he
 * on 2020/6/1
 */
@Service
@ChannelHandler.Sharable
public class RemoteClientHandler extends ChannelInboundHandlerAdapter {
    @Autowired
    private ChannelProxy channelProxy;

    @Autowired
    private MethodClass methodClass;

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {

    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        channelProxy.sendMessage(ctx, methodClass.getSendMessage(100, 200));
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        super.channelReadComplete(ctx);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx, cause);
        ctx.close();
    }



}
